package com.exp.controller;
import com.exp.dto.JobPageQueryDTO;
import com.exp.pojo.JobInf;
import com.exp.result.PageResult;
import com.exp.result.Result;
import com.exp.result.StatusCode;
import com.exp.service.JobInfService;
import com.exp.utils.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 职位管理模块-pyz
 */
@RestController
@RequestMapping("/admin/jobInf")
@Slf4j
public class JobInfController {

    @Autowired
    private JobInfService jobInfService;

    /*
     * 职位查询-分页查询
     * 搜索条件：职位名称
     */
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody JobPageQueryDTO jobPageQueryDTO){
        PageResult pageResult = jobInfService.pageQuery(jobPageQueryDTO);
        return Result.success(StatusCode.SUCCESS, Message.PAGE_SUCCESS,pageResult);
    }

    /*
     * 添加职位
     * 输入：职位名称、详细描述
     */
//    @CrossOrigin(origins = "http://172.20.10.6:5173")
    @PostMapping("/add")
    public Result<JobInf> save(@RequestBody JobInf jobInf){
        log.info("新增职位：{}",jobInf);
        jobInfService.save(jobInf);
        return Result.success(StatusCode.SUCCESS,Message.SAVE_SUCCESS,jobInf);
    }

    /*
     * 修改职位
     * 输入：职位名称、详细描述
     */
//    @CrossOrigin(origins = "http://172.20.10.6:5173")
    @PutMapping("/update")
    public Result update(@RequestBody JobInf jobInf){
        log.info("编辑职位信息：{}", jobInf);
        jobInfService.update(jobInf);
        return Result.success(StatusCode.SUCCESS,Message.UPDATE_SUCCESS,jobInf);
    }


    /*
    批量删除
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Integer> ids) {
        jobInfService.deleteBatch(ids);
        return Result.success(StatusCode.SUCCESS,Message.DELETE_SUCCESS,ids);
    }


}
